package com.controller.hotel;

import com.biz.HotelMenuBiz;
import com.biz.MenuInfoBiz;
import com.controller.backend.BaseController;
import com.core.Result;
import com.core.ResultGenerator;
import com.entity.model.HotelAdmin;
import com.entity.model.HotelMenu;
import com.entity.model.ManagerInfo;
import com.entity.model.MenuInfo;
import com.util.SystemConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by asan on 2017/09/17.
 */
@Controller
@RequestMapping("/hotel/security/menu")
public class HotelMenuInfoController extends BaseController<HotelMenu> {

    @Autowired
    private HotelMenuBiz hotelMenuBiz;


    @SuppressWarnings("unchecked")
    @RequestMapping(value = "getMenu")
    @ResponseBody
    public Result getMenu(HttpSession session) {
        HotelAdmin managerInfo = (HotelAdmin) session.getAttribute(SystemConstant.SESSION_HOTEL_ADMIN);
        if (managerInfo == null) {
            return ResultGenerator.genFailResult("/hotel/loginIndex");
        } else {
            List<HotelMenu> list;
            list = hotelMenuBiz.findAll();
            session.setAttribute(SystemConstant.SESSION_RIGHT_LIST, list);

            Map res = new HashMap(2);
            res.put("account", managerInfo);
            res.put("menu", list);
            return ResultGenerator.genSuccessResult(res);
        }
    }

    //获取所有后台菜单按钮
    @RequestMapping(value = "getMenuInfo")
    @ResponseBody
    public Result getMenuInfo(HttpSession session) {
        List<HotelMenu> list = hotelMenuBiz.findAll();
        session.setAttribute(SystemConstant.SESSION_RIGHT_LIST, list);
        return ResultGenerator.genSuccessResult(list);

    }


    @RequestMapping(value = "getList")
    @ResponseBody
    public Result getList(HotelMenu hotelMenu) {
        List<HotelMenu> list = baseBiz.findAll();
        return ResultGenerator.genSuccessResult(list);
    }
}
